package com.sky.controller.user;

import com.sky.dto.UserLoginDTO;
import com.sky.result.Result;
import com.sky.service.UserService;
import com.sky.vo.UserLoginVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@Slf4j
@RestController
@Api(tags = "用户控制器")
@RequestMapping("/user/user")
public class UserController {

    @Resource
    UserService userService;

    @PostMapping("/login")
    @ApiOperation("用户登录")
    public Result<UserLoginVO> login(@RequestBody UserLoginDTO userLoginDTO){
        log.info("[客户端用户登录] 开始执行");
        UserLoginVO userLoginVO = userService.login(userLoginDTO);
        log.info("[客户端用户登录] 执行成功"); //不再进行判断是否登录成功,登录失败时直接抛出异常让全局异常处理器来进行处理,运行到这里就说明肯定登录成功了
        return Result.success(userLoginVO);
    }
}
